package com.group.lyl.send.task;

import com.group.lyl.send.model.Staff;
import com.group.lyl.send.service.StaffService;
import com.group.lyl.send.service.impl.SendMailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 每日0时定时检测当天是否有员工生日发送邮件
 */

@Component
@EnableScheduling
public class sendMailTask {

    @Autowired
    private StaffService staffService;

    @Autowired
    private SendMailService sendMailService;

    @Scheduled(cron = "0 0 0 * * ?")
    public void sendMail(){
        Date now = new Date();
        List<Staff> byBirthday = staffService.findByBirthday(now);
        for (Staff staff : byBirthday) {
            sendMailService.sendMail(staff);
        }


    }


}
